﻿var ECode = function(){
    this.showHideCode = function(divid, tsn){
        var _divid = document.getElementById(divid);
        var _tsn = document.getElementById(tsn);
        var _drs = this.getElementsByName_iefix("td", divid);
        if (_divid.style.display == "none") {
            _divid.style.display = "inline";
            _tsn.style.display = "none";
            for (var i = 0; i < _drs.length; i++) {
                _drs[i].style.display = "inline";
            }
            
        }
        else {
            _divid.style.display = "none";
            _tsn.style.display = "inline";
            for (var i = 0; i < _drs.length; i++) {
                _drs[i].style.display = "none";
            }
        }
    };
    this.getStyle = function(ele, value){
        var rs;
        if (ele.style[value]) {
            rs = ele.style[value];
        }
        else 
            if (window.getComputedStyle) {
                value = value.replace(/([A-Z])/g, "-$1");
                rs = window.getComputedStyle(ele, "").getPropertyValue(value);
                if (value == "color") {
                    rs = this.colorToHex(rs);
                }
            }
            else 
                if (ele.currentStyle) {
                    rs = ele.currentStyle[value];
                }
                else {
                    return null;
                }
        return rs;
    };
    this.colorToHex = function(color){
        var rgb = /rgb\((\d{1,3}),(\s)*(\d{1,3}),(\s)*(\d{1,3})\)/;
        var noun = /^\w+/; //预命名颜色正刿
        var rs;
        if (rgb.test(color)) {
            var rgbfix = rgb.exec(color);
            var r, g, b;
            r = parseInt(rgbfix[1]).toString(16);
            g = parseInt(rgbfix[3]).toString(16);
            b = parseInt(rgbfix[5]).toString(16);
            rs = "#" + (r < 10 ? "0" + r : r) + (g < 10 ? "0" + g : g) + (b < 10 ? "0" + b : b);
        }
        else {
            rs = color;
        }
        if (rs.length == 4 && !noun.test(rs)) {
            rs = rs + rs.split("#")[1]
        }
        return rs;
    };
    
    this.HexToR = function(h){
        return parseInt((this.cutHex(h)).substring(0, 2), 16);
    };
    this.HexToG = function(h){
        return parseInt((this.cutHex(h)).substring(2, 4), 16);
    };
    this.HexToB = function(h){
        return parseInt((this.cutHex(h)).substring(4, 6), 16);
    };
    this.cutHex = function(h){
        return (h.charAt(0) == "#") ? h.substring(1, 7) : h;
    };
    this.RGBtoHex = function(R, G, B){
        return "#" + this.toHex(R) + this.toHex(G) + this.toHex(B);
    };
    this.toHex = function(N){
        if (N == null) 
            return "00";
        N = parseInt(N);
        if (N == 0 || isNaN(N)) 
            return "00";
        N = Math.max(0, N);
        N = Math.min(N, 255);
        N = Math.round(N);
        return "0123456789ABCDEF".charAt((N - N % 16) / 16) + "0123456789ABCDEF".charAt(N % 16);
    };
    this.hex2rgb = function(hex){
        var c, o = [], k = 0, m = hex.match(/^#(([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})|([0-9a-f])([0-9a-f])([0-9a-f]))$/i);
        if (!m) 
            return {
                r: 0,
                g: 0,
                b: 0
            };
        for (var i = 2, s = m.length; i < s; i++) {
            if (undefined === m[i]) 
                continue;
            c = parseInt(m[i], 16);
            o[k++] = c + (i > 4 ? c * 16 : 0);
        }
        return {
            r: o[0],
            g: o[1],
            b: o[2]
        };
    };
    this.getElementsByName_iefix = function(tag, name){
        var elem = document.getElementsByTagName(tag);
        var arr = new Array();
        for (i = 0, iarr = 0; i < elem.length; i++) {
            att = elem[i].getAttribute("name");
            if (att == name) {
                arr[iarr] = elem[i];
                iarr++;
            }
        }
        return arr;
    };
    this.getElementPos = function(elementId){
        var ua = navigator.userAgent.toLowerCase();
        var isOpera = (ua.indexOf("opera") != -1);
        var isIE = (ua.indexOf("msie") != -1 && !isOpera); // not opera spoof 
        var el = document.getElementById(elementId);
        if (el.parentNode === null || el.style.display == "none") {
            return false;
        }
        var parent = null;
        var pos = [];
        var box;
        if (el.getBoundingClientRect) //IE 
        {
            box = el.getBoundingClientRect();
            var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
            var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
            
            return {
                x: box.left + scrollLeft,
                y: box.top + scrollTop
            };
        }
        else 
            if (document.getBoxObjectFor) // gecko 
            {
                box = document.getBoxObjectFor(el);
                
                var borderLeft = (el.style.borderLeftWidth) ? parseInt(el.style.borderLeftWidth) : 0;
                var borderTop = (el.style.borderTopWidth) ? parseInt(el.style.borderTopWidth) : 0;
                
                pos = [box.x - borderLeft, box.y - borderTop];
            }
            else // safari & opera 
            {
                pos = [el.offsetLeft, el.offsetTop];
                parent = el.offsetParent;
                if (parent != el) {
                    while (parent) {
                        pos[0] += parent.offsetLeft;
                        pos[1] += parent.offsetTop;
                        parent = parent.offsetParent;
                    }
                }
                if (ua.indexOf("opera") != -1 || (ua.indexOf("safari") != -1 && el.style.position == "absolute")) {
                    pos[0] -= document.body.offsetLeft;
                    pos[1] -= document.body.offsetTop;
                }
            }
        if (el.parentNode) {
            parent = el.parentNode;
        }
        else {
            parent = null;
        }
        while (parent && parent.tagName != "BODY" && parent.tagName != "HTML") { // account for any scrolled ancestors 
            pos[0] -= parent.scrollLeft;
            pos[1] -= parent.scrollTop;
            if (parent.parentNode) {
                parent = parent.parentNode;
            }
            else {
                parent = null;
            }
        }
        return {
            x: pos[0],
            y: pos[1]
        };
    };
    this.getViewportHeight = function(){
        var height = 0;
        if (window.innerHeight) {
            height = window.innerHeight;
        }
        else 
            if (document.documentElement && document.documentElement.clientHeight) {
                height = document.documentElement.clientHeight;
            }
            else 
                if (document.body && document.body.clientHeight) {
                    height = document.body.clientHeight;
                }
        return height;
    };
    this.getViewportWidth = function(){
        var width = 0;
        if (window.innerWidth) {
            width = window.innerWidth;
        }
        else 
            if (document.documentElement && document.documentElement.clientWidth) {
                width = document.documentElement.clientWidth;
            }
            else 
                if (document.body && document.body.clientWidth) {
                    width = document.body.clientWidth;
                }
        return width;
    };
    this.xmlrequest = false;
    this.createXMLHTTP = function(){
        var xmlhttp = null;
        if (window.ActiveXObject) {
            try {
                xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
            } 
            catch (e) {
                try {
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                } 
                catch (e) {
                }
            }
        }
        else 
            if (window.XMLHttpRequest) {
                xmlhttp = new XMLHttpRequest();
                if (xmlhttp.overrideMimeType) {
                    xmlhttp.overrideMimeType("text/xml");
                }
            }
            else {
                alert("Create XMLHttpRequest object false!");
                return false;
            }
        return xmlhttp;
    };
    this.InitObject = function(){
        if (!this.xmlrequest) {
            this.xmlrequest = this.createXMLHTTP();
        }
    };
    this.CallServer = function(id){
        if (!this.xmlrequest) {
            this.InitObject();
        }
        var that = this;
        if (this.xmlrequest) {
            var url;
            var mypanel = this.showForm(id);
            var pname = document.getElementById(id).innerText;
            switch (pname) {
                case "×":
                    pname = "相乘";
                    break;
                case "÷":
                    pname = "相除";
                    break;
            }
            url = "http://www.jiesoft.com.cn/999999101017T9A1DKK6/demo_getdata_ind.php?name=" + escape(pname) + "&rnd=" + (new Date());
            this.xmlrequest.open("GET", url, true);
            this.xmlrequest.onreadystatechange = function(){
                that.UpdatePage(mypanel);
            };
            this.xmlrequest.send(null);
        }
    };
    this.UpdatePage = function(mypanel){
        if (this.xmlrequest.readyState == 4) {
            var response = this.xmlrequest.responseText;
            mypanel.el.innerHTML = unescape(response);
            mypanel.fn();
        }
    };
    this.isIE = (document.all) ? true : false;
    this.$ = function(id){
        return "string" == typeof id ? document.getElementById(id) : id;
    };
    this.Extend = function(destination, source){
        for (var property in source) {
            destination[property] = source[property];
        }
    };
    this.Bind = function(object, fun){
        return function(){
            return fun.apply(object, arguments);
        }
    };
    this.BindAsEventListener = function(object, fun){
        var args = Array.prototype.slice.call(arguments).slice(2);
        return function(event){
            return fun.apply(object, [event || window.event].concat(args));
        }
    };
    this.CurrentStyle = function(element){
        return element.currentStyle || document.defaultView.getComputedStyle(element, null);
    };
    this.addEventHandler = function(oTarget, sEventType, fnHandler){
        if (oTarget.addEventListener) {
            oTarget.addEventListener(sEventType, fnHandler, false);
        }
        else 
            if (oTarget.attachEvent) {
                oTarget.attachEvent("on" + sEventType, fnHandler);
            }
            else {
                oTarget["on" + sEventType] = fnHandler;
            }
    };
    this.removeEventHandler = function(oTarget, sEventType, fnHandler){
        if (oTarget.removeEventListener) {
            oTarget.removeEventListener(sEventType, fnHandler, false);
        }
        else 
            if (oTarget.detachEvent) {
                oTarget.detachEvent("on" + sEventType, fnHandler);
            }
            else {
                oTarget["on" + sEventType] = null;
            }
    };
    //缩放程序
    this.Resize = function(){
        this.initialize.apply(this, arguments);
    };
    this.Resize.prototype = {
        //缩放对象
        objecode: null,
        initialize: function(myecode, obj, options){
            objecode = myecode;
            this._obj = objecode.$(obj);//缩放对象
            this._styleWidth = this._styleHeight = this._styleLeft = this._styleTop = 0;//样式参数
            this._sideRight = this._sideDown = this._sideLeft = this._sideUp = 0;//坐标参数
            this._fixLeft = this._fixTop = 0;//定位参数
            this._scaleLeft = this._scaleTop = 0;//定位坐标
            this._mxSet = function(){
            };//范围设置程序
            this._mxRightWidth = this._mxDownHeight = this._mxUpHeight = this._mxLeftWidth = 0;//范围参数
            this._mxScaleWidth = this._mxScaleHeight = 0;//比例范围参数
            this._fun = function(){
            };//缩放执行程序
            //获取边框宽度
            var _style = objecode.CurrentStyle(this._obj);
            this._borderX = (parseInt(_style.borderLeftWidth) || 0) + (parseInt(_style.borderRightWidth) || 0);
            this._borderY = (parseInt(_style.borderTopWidth) || 0) + (parseInt(_style.borderBottomWidth) || 0);
            //事件对象(用于绑定移除事件)
            this._fR = objecode.BindAsEventListener(this, this.Resize);
            this._fS = objecode.Bind(this, this.Stop);
            
            this.SetOptions(options);
            //范围限制
            this.Max = !!this.options.Max;
            this._mxContainer = objecode.$(this.options.mxContainer) || null;
            this.mxLeft = Math.round(this.options.mxLeft);
            this.mxRight = Math.round(this.options.mxRight);
            this.mxTop = Math.round(this.options.mxTop);
            this.mxBottom = Math.round(this.options.mxBottom);
            //宽高限制
            this.Min = !!this.options.Min;
            this.minWidth = Math.round(this.options.minWidth);
            this.minHeight = Math.round(this.options.minHeight);
            //按比例缩政
            this.Scale = !!this.options.Scale;
            this.Ratio = Math.max(this.options.Ratio, 0);
            
            this.onResize = this.options.onResize;
            
            this._obj.style.position = "absolute";
            !this._mxContainer || CurrentStyle(this._mxContainer).position == "relative" || (this._mxContainer.style.position = "relative");
        },
        //设置默认属怿
        SetOptions: function(options){
            this.options = {//默认倿
                Max: false,//是否设置范围限制(为true时下面mx参数有用)
                mxContainer: "",//指定限制在容器内
                mxLeft: 0,//左边限制
                mxRight: 9999,//右边限制
                mxTop: 0,//上边限制
                mxBottom: 9999,//下边限制
                Min: false,//是否最小宽高限刿为true时下面min参数有用)
                minWidth: 50,//最小宽庿
                minHeight: 50,//最小高庿
                Scale: false,//是否按比例缩政
                Ratio: 0,//缩放比例(宿髿
                onResize: function(){
                }//缩放时执衿
            };
            objecode.Extend(this.options, options || {});
        },
        //设置触发对象
        Set: function(resize, side){
            var resize = objecode.$(resize), fun;
            if (!resize) 
                return;
            //根据方向设置
            switch (side.toLowerCase()) {
                case "up":
                    fun = this.Up;
                    break;
                case "down":
                    fun = this.Down;
                    break;
                case "left":
                    fun = this.Left;
                    break;
                case "right":
                    fun = this.Right;
                    break;
                case "left-up":
                    fun = this.LeftUp;
                    break;
                case "right-up":
                    fun = this.RightUp;
                    break;
                case "left-down":
                    fun = this.LeftDown;
                    break;
                case "right-down":
                default:
                    fun = this.RightDown;
            };
            //设置触发对象
            objecode.addEventHandler(resize, "mousedown", objecode.BindAsEventListener(this, this.Start, fun));
        },
        //准备缩放
        Start: function(e, fun, touch){
            //防止冒泡(跟拖放配合时设置)
            e.stopPropagation ? e.stopPropagation() : (e.cancelBubble = true);
            //设置执行程序
            this._fun = fun;
            //样式参数倿
            this._styleWidth = this._obj.clientWidth;
            this._styleHeight = this._obj.clientHeight;
            this._styleLeft = this._obj.offsetLeft;
            this._styleTop = this._obj.offsetTop;
            //四条边定位坐栿
            this._sideLeft = e.clientX - this._styleWidth;
            this._sideRight = e.clientX + this._styleWidth;
            this._sideUp = e.clientY - this._styleHeight;
            this._sideDown = e.clientY + this._styleHeight;
            //top和left定位参数
            this._fixLeft = this._styleLeft + this._styleWidth;
            this._fixTop = this._styleTop + this._styleHeight;
            //缩放比例
            if (this.Scale) {
                //设置比例
                this.Ratio = Math.max(this.Ratio, 0) || this._styleWidth / this._styleHeight;
                //left和top的定位坐栿
                this._scaleLeft = this._styleLeft + this._styleWidth / 2;
                this._scaleTop = this._styleTop + this._styleHeight / 2;
            };
            //范围限制
            if (this.Max) {
                //设置范围参数
                var mxLeft = this.mxLeft, mxRight = this.mxRight, mxTop = this.mxTop, mxBottom = this.mxBottom;
                //如果设置了容器，再修正范围参敿
                if (!!this._mxContainer) {
                    mxLeft = Math.max(mxLeft, 0);
                    mxTop = Math.max(mxTop, 0);
                    mxRight = Math.min(mxRight, this._mxContainer.clientWidth);
                    mxBottom = Math.min(mxBottom, this._mxContainer.clientHeight);
                };
                //根据最小值再修正
                mxRight = Math.max(mxRight, mxLeft + (this.Min ? this.minWidth : 0) + this._borderX);
                mxBottom = Math.max(mxBottom, mxTop + (this.Min ? this.minHeight : 0) + this._borderY);
                //由于转向时要重新设置所以写成function形式
                this._mxSet = function(){
                    this._mxRightWidth = mxRight - this._styleLeft - this._borderX;
                    this._mxDownHeight = mxBottom - this._styleTop - this._borderY;
                    this._mxUpHeight = Math.max(this._fixTop - mxTop, this.Min ? this.minHeight : 0);
                    this._mxLeftWidth = Math.max(this._fixLeft - mxLeft, this.Min ? this.minWidth : 0);
                };
                this._mxSet();
                //有缩放比例下的范围限刿
                if (this.Scale) {
                    this._mxScaleWidth = Math.min(this._scaleLeft - mxLeft, mxRight - this._scaleLeft - this._borderX) * 2;
                    this._mxScaleHeight = Math.min(this._scaleTop - mxTop, mxBottom - this._scaleTop - this._borderY) * 2;
                };
                            };
            //mousemove时缩政mouseup时停歿
            objecode.addEventHandler(document, "mousemove", this._fR);
            objecode.addEventHandler(document, "mouseup", this._fS);
            if (objecode.isIE) {
                objecode.addEventHandler(this._obj, "losecapture", this._fS);
                this._obj.setCapture();
            }
            else {
                objecode.addEventHandler(window, "blur", this._fS);
                e.preventDefault();
            };
                    },
        //缩放
        Resize: function(e){
            //清除选择
            window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
            //执行缩放程序
            this._fun(e);
            //设置样式，变量必须大于等亿否则ie出错
            with (this._obj.style) {
                width = this._styleWidth + "px";
                height = this._styleHeight + "px";
                top = this._styleTop + "px";
                left = this._styleLeft + "px";
            }
            //附加程序
            this.onResize();
        },
        //缩放程序
        //丿
        Up: function(e){
            this.RepairY(this._sideDown - e.clientY, this._mxUpHeight);
            this.RepairTop();
            this.TurnDown(this.Down);
        },
        //丿
        Down: function(e){
            this.RepairY(e.clientY - this._sideUp, this._mxDownHeight);
            this.TurnUp(this.Up);
        },
        //叿
        Right: function(e){
            this.RepairX(e.clientX - this._sideLeft, this._mxRightWidth);
            this.TurnLeft(this.Left);
        },
        //巿
        Left: function(e){
            this.RepairX(this._sideRight - e.clientX, this._mxLeftWidth);
            this.RepairLeft();
            this.TurnRight(this.Right);
        },
        //右下
        RightDown: function(e){
            this.RepairAngle(e.clientX - this._sideLeft, this._mxRightWidth, e.clientY - this._sideUp, this._mxDownHeight);
            this.TurnLeft(this.LeftDown) || this.TurnUp(this.RightUp);
        },
        //右上
        RightUp: function(e){
            this.RepairAngle(e.clientX - this._sideLeft, this._mxRightWidth, this._sideDown - e.clientY, this._mxUpHeight);
            this.RepairTop();
            this.TurnLeft(this.LeftUp) || this.TurnDown(this.RightDown);
        },
        //左下
        LeftDown: function(e){
            this.RepairAngle(this._sideRight - e.clientX, this._mxLeftWidth, e.clientY - this._sideUp, this._mxDownHeight);
            this.RepairLeft();
            this.TurnRight(this.RightDown) || this.TurnUp(this.LeftUp);
        },
        //左上
        LeftUp: function(e){
            this.RepairAngle(this._sideRight - e.clientX, this._mxLeftWidth, this._sideDown - e.clientY, this._mxUpHeight);
            this.RepairTop();
            this.RepairLeft();
            this.TurnRight(this.RightUp) || this.TurnDown(this.LeftDown);
        },
        //修正程序
        //水平方向
        RepairX: function(iWidth, mxWidth){
            iWidth = this.RepairWidth(iWidth, mxWidth);
            if (this.Scale) {
                var iHeight = Math.round(iWidth / this.Ratio);
                if (this.Max && iHeight > this._mxScaleHeight) {
                    iWidth = Math.round((iHeight = this._mxScaleHeight) * this.Ratio);
                }
                else 
                    if (this.Min && iHeight < this.minHeight) {
                        var tWidth = Math.round(this.minHeight * this.Ratio);
                        if (tWidth < mxWidth) {
                            iHeight = this.minHeight;
                            iWidth = tWidth;
                        }
                    }
                this._styleHeight = iHeight;
                this._styleTop = this._scaleTop - iHeight / 2;
            }
            this._styleWidth = iWidth;
        },
        //垂直方向
        RepairY: function(iHeight, mxHeight){
            iHeight = this.RepairHeight(iHeight, mxHeight);
            if (this.Scale) {
                var iWidth = Math.round(iHeight * this.Ratio);
                if (this.Max && iWidth > this._mxScaleWidth) {
                    iHeight = Math.round((iWidth = this._mxScaleWidth) / this.Ratio);
                }
                else 
                    if (this.Min && iWidth < this.minWidth) {
                        var tHeight = Math.round(this.minWidth / this.Ratio);
                        if (tHeight < mxHeight) {
                            iWidth = this.minWidth;
                            iHeight = tHeight;
                        }
                    }
                this._styleWidth = iWidth;
                this._styleLeft = this._scaleLeft - iWidth / 2;
            }
            this._styleHeight = iHeight;
        },
        //对角方向
        RepairAngle: function(iWidth, mxWidth, iHeight, mxHeight){
            iWidth = this.RepairWidth(iWidth, mxWidth);
            if (this.Scale) {
                iHeight = Math.round(iWidth / this.Ratio);
                if (this.Max && iHeight > mxHeight) {
                    iWidth = Math.round((iHeight = mxHeight) * this.Ratio);
                }
                else 
                    if (this.Min && iHeight < this.minHeight) {
                        var tWidth = Math.round(this.minHeight * this.Ratio);
                        if (tWidth < mxWidth) {
                            iHeight = this.minHeight;
                            iWidth = tWidth;
                        }
                    }
            }
            else {
                iHeight = this.RepairHeight(iHeight, mxHeight);
            }
            this._styleWidth = iWidth;
            this._styleHeight = iHeight;
        },
        //top
        RepairTop: function(){
            this._styleTop = this._fixTop - this._styleHeight;
        },
        //left
        RepairLeft: function(){
            this._styleLeft = this._fixLeft - this._styleWidth;
        },
        //height
        RepairHeight: function(iHeight, mxHeight){
            iHeight = Math.min(this.Max ? mxHeight : iHeight, iHeight);
            iHeight = Math.max(this.Min ? this.minHeight : iHeight, iHeight, 0);
            return iHeight;
        },
        //width
        RepairWidth: function(iWidth, mxWidth){
            iWidth = Math.min(this.Max ? mxWidth : iWidth, iWidth);
            iWidth = Math.max(this.Min ? this.minWidth : iWidth, iWidth, 0);
            return iWidth;
        },
        //转向程序
        //转右
        TurnRight: function(fun){
            if (!(this.Min || this._styleWidth)) {
                this._fun = fun;
                this._sideLeft = this._sideRight;
                this.Max && this._mxSet();
                return true;
            }
        },
        //转左
        TurnLeft: function(fun){
            if (!(this.Min || this._styleWidth)) {
                this._fun = fun;
                this._sideRight = this._sideLeft;
                this._fixLeft = this._styleLeft;
                this.Max && this._mxSet();
                return true;
            }
        },
        //转上
        TurnUp: function(fun){
            if (!(this.Min || this._styleHeight)) {
                this._fun = fun;
                this._sideDown = this._sideUp;
                this._fixTop = this._styleTop;
                this.Max && this._mxSet();
                return true;
            }
        },
        //转下
        TurnDown: function(fun){
            if (!(this.Min || this._styleHeight)) {
                this._fun = fun;
                this._sideUp = this._sideDown;
                this.Max && this._mxSet();
                return true;
            }
        },
        //停止缩放
        Stop: function(){
            objecode.removeEventHandler(document, "mousemove", this._fR);
            objecode.removeEventHandler(document, "mouseup", this._fS);
            if (objecode.isIE) {
                objecode.removeEventHandler(this._obj, "losecapture", this._fS);
                this._obj.releaseCapture();
            }
            else {
                objecode.removeEventHandler(window, "blur", this._fS);
            }
        }
    };
    //拖放程序
    this.Drag = function(){
        this.initialize.apply(this, arguments);
    };
    this.Drag.prototype = {
        objecode: null,
        //拖放对象
        initialize: function(myecode, drag, options){
            objecode = myecode;
            
            this.Drag = myecode.$(drag);//拖放对象
            this._x = this._y = 0;//记录鼠标相对拖放对象的位罿
            this._marginLeft = this._marginTop = 0;//记录margin
            //事件对象(用于绑定移除事件)
            this._fM = objecode.BindAsEventListener(this, this.Move);
            this._fS = objecode.Bind(this, this.Stop);
            
            this.SetOptions(options);
            
            this.Limit = !!this.options.Limit;
            this.mxLeft = parseInt(this.options.mxLeft);
            this.mxRight = parseInt(this.options.mxRight);
            this.mxTop = parseInt(this.options.mxTop);
            this.mxBottom = parseInt(this.options.mxBottom);
            
            this.LockX = !!this.options.LockX;
            this.LockY = !!this.options.LockY;
            this.Lock = !!this.options.Lock;
            
            this.onStart = this.options.onStart;
            this.onMove = this.options.onMove;
            this.onStop = this.options.onStop;
            
            this._Handle = objecode.$(this.options.Handle) || this.Drag;
            this._mxContainer = objecode.$(this.options.mxContainer) || null;
            
            this.Drag.style.position = "absolute";
            //透明
            if (objecode.isIE && !!this.options.Transparent) {
                //填充拖放对象
                with (this._Handle.appendChild(document.createElement("div")).style) {
                    width = height = "100%";
                    backgroundColor = "#fff";
                    filter = "alpha(opacity:0)";
                }
            }
            //修正范围
            this.Repair();
            myecode.addEventHandler(this._Handle, "mousedown", objecode.BindAsEventListener(this, this.Start));
        },
        //设置默认属性
        SetOptions: function(options){
            this.options = {//默认
                Handle: "",//设置触发对象（不设置则使用拖放对象）
                Limit: false,//是否设置范围限制(为true时下面参数有甿可以是负敿
                mxLeft: 0,//左边限制
                mxRight: 9999,//右边限制
                mxTop: 0,//上边限制
                mxBottom: 9999,//下边限制
                mxContainer: "",//指定限制在容器内
                LockX: false,//是否锁定水平方向拖放
                LockY: false,//是否锁定垂直方向拖放
                Lock: false,//是否锁定
                Transparent: false,//是否透明
                onStart: function(){
                },//开始移动时执行
                onMove: function(){
                },//移动时执衿
                onStop: function(){
                }//结束移动时执衿
            };
            myecode.Extend(this.options, options || {});
        },
        //准备拖动
        Start: function(oEvent){
            if (this.Lock) {
                return;
            }
            this.Repair();
            //记录鼠标相对拖放对象的位罿
            this._x = oEvent.clientX - this.Drag.offsetLeft;
            this._y = oEvent.clientY - this.Drag.offsetTop;
            //记录margin
            this._marginLeft = parseInt(objecode.CurrentStyle(this.Drag).marginLeft) || 0;
            this._marginTop = parseInt(objecode.CurrentStyle(this.Drag).marginTop) || 0;
            //mousemove时移势mouseup时停歿
            objecode.addEventHandler(document, "mousemove", this._fM);
            objecode.addEventHandler(document, "mouseup", this._fS);
            if (objecode.isIE) {
                //焦点丢失
                objecode.addEventHandler(this._Handle, "losecapture", this._fS);
                //设置鼠标捕获
                this._Handle.setCapture();
            }
            else {
                //焦点丢失
                objecode.addEventHandler(window, "blur", this._fS);
                //阻止默认动作
                oEvent.preventDefault();
            };
            //附加程序
            this.onStart();
        },
        //修正范围
        Repair: function(){
            if (this.Limit) {
                //修正错误范围参数
                this.mxRight = Math.max(this.mxRight, this.mxLeft + this.Drag.offsetWidth);
                this.mxBottom = Math.max(this.mxBottom, this.mxTop + this.Drag.offsetHeight);
                //如果有容器必须设置position为relative来相对定位，并在获取offset之前设置
                !this._mxContainer || myecode.CurrentStyle(this._mxContainer).position == "relative" || (this._mxContainer.style.position = "relative");
            }
        },
        //拖动
        Move: function(oEvent){
            //判断是否锁定
            if (this.Lock) {
                this.Stop();
                return;
            };
            //清除选择
            window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
            //设置移动参数
            var iLeft = oEvent.clientX - this._x, iTop = oEvent.clientY - this._y;
            //设置范围限制
            if (this.Limit) {
                //设置范围参数
                var mxLeft = this.mxLeft, mxRight = this.mxRight, mxTop = this.mxTop, mxBottom = this.mxBottom;
                //如果设置了容器，再修正范围参敿
                if (!!this._mxContainer) {
                    mxLeft = Math.max(mxLeft, 0);
                    mxTop = Math.max(mxTop, 0);
                    mxRight = Math.min(mxRight, this._mxContainer.clientWidth);
                    mxBottom = Math.min(mxBottom, this._mxContainer.clientHeight);
                };
                //修正移动参数
                iLeft = Math.max(Math.min(iLeft, mxRight - this.Drag.offsetWidth), mxLeft);
                iTop = Math.max(Math.min(iTop, mxBottom - this.Drag.offsetHeight), mxTop);
            }
            //设置位置，并修正margin
            if (!this.LockX) {
                this.Drag.style.left = iLeft - this._marginLeft + "px";
            }
            if (!this.LockY) {
                this.Drag.style.top = iTop - this._marginTop + "px";
            }
            //附加程序
            this.onMove();
        },
        //停止拖动
        Stop: function(){
            //移除事件
            objecode.removeEventHandler(document, "mousemove", this._fM);
            objecode.removeEventHandler(document, "mouseup", this._fS);
            if (objecode.isIE) {
                objecode.removeEventHandler(this._Handle, "losecapture", this._fS);
                this._Handle.releaseCapture();
            }
            else {
                objecode.removeEventHandler(window, "blur", this._fS);
            };
            //附加程序
            this.onStop();
        }
    };
    this.newSn = function(type, subtype){
        var sn = type + subtype;
        var seed = new Array("ABCDEFGHIJKLMNOPQRSTUVWXYZ", "0123456789");
        for (var i = 0; i < 14; i++) {
            idx = Math.floor(Math.random() * 2);
            sn += seed[idx].substr(Math.floor(Math.random() * (seed[idx].length)), 1);
        }
        return sn;
    };
    this._getClose = function(){
        var dots = new Array(new Array(1, 0, 0, 0, 0, 0, 1), new Array(0, 1, 0, 0, 0, 1, 0), new Array(0, 0, 1, 0, 1, 0, 0), new Array(0, 0, 0, 1, 0, 0, 0), new Array(0, 0, 1, 0, 1, 0, 0), new Array(0, 1, 0, 0, 0, 1, 0), new Array(1, 0, 0, 0, 0, 0, 1));
        var html = '';
        html += "<div class='PWHYLR9UEZ5LPA2KWI6Z'>";
        for (var i = 0; i < dots.length; i++) {
            for (var j = 0; j < dots[i].length; j++) {
                if (dots[i][j]) {
                    html += "<div class='PWHYLR9UEZ5LGKQ5BBN3' style='left:" + j + "px; top:" +
                    i +
                    "px;'>&nbsp;</div>";
                }
            }
        }
        html += "</div>";
        return html;
    }
    this.showForm = function(id){
        var mydiv = document.createElement("div");
        
        var closediv = document.createElement("div");
        closediv.className = "CL9999101105SWB5RI52";
        closediv.innerHTML = this._getClose();
        mydiv.appendChild(closediv);
        this.addEventHandler(closediv, "click", function(){
            mydiv.parentNode.removeChild(mydiv);
        });
        var contentdiv = document.createElement("div");
        contentdiv.className = "CL9999101105OQXAMOYI";
        contentdivid = this.newSn("TM", "0001");
        contentdiv.id = contentdivid;
        
        var contentct = document.createElement("div");
        contentct.className = "CL9999101110DFJSFPPA";
        contentctid = this.newSn("TM", "0001");
        contentct.id = contentctid;
        contentdiv.appendChild(contentct);
        
        var contents = document.createElement("div");
        contents.innerHTML = "<EMBED pluginspage='http://www.macromedia.com/go/getflashplayer' src='media/loading.swf' type='application/x-shockwave-flash' height='55' width='55' wmode='transparent'	quality='high'></EMBED>";
        contents.className = "CL9999101105SAOJKWWE";
        contentsid = this.newSn("TM", "0001");
        contents.id = contentsid;
		
        contentct.appendChild(contents);
        
        
        var remarkdiv = document.createElement("div");
        remarkdiv.innerHTML = "来源:易语言知识库";
        remarkdiv.className = "CL99991011095X1EE5FR";
        mydiv.appendChild(remarkdiv);
        
        mydiv.appendChild(contentdiv);
        
        mydiv.className = "CL9999101105TNM1TZ6H";
        mydivid = this.newSn("TM", "0001");
        mydiv.id = mydivid;
        
        var scrolldiv = document.createElement("div");
        scrolldiv.className = "CL9999101110ZDDC45XK";
        mydiv.appendChild(scrolldiv);
        
        var scrollctdiv = document.createElement("div");
        scrollctdivid = this.newSn("TM", "0001");
        scrollctdiv.id = scrollctdivid;
        scrollctdiv.className = "CL99991011102LPQ0EYQ";
        scrolldiv.appendChild(scrollctdiv);
        
        var scrollbardiv = document.createElement("div");
        scrollbardiv.innerHTML = new Array(document.body.offsetHeight).join("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>");
        scrollbardivid = this.newSn("TM", "0001");
        scrollbardiv.id = scrollbardivid;
        scrollbardiv.className = "CL9999101110L12JK3VB";
        scrollctdiv.appendChild(scrollbardiv);
        
        
        rRightDownId = this.newSn("TM", "0001");
        rLeftDownId = this.newSn("TM", "0001");
        rRightUpId = this.newSn("TM", "0001");
        rLeftUpId = this.newSn("TM", "0001");
        rUpId = this.newSn("TM", "0001");
        rDownId = this.newSn("TM", "0001");
        rLeftId = this.newSn("TM", "0001");
        rRightId = this.newSn("TM", "0001");
        
        var rRightDown = document.createElement("div");
        rRightDown.id = rRightDownId;
        rRightDown.className = "CL9999101105PKTOHBZA";
        mydiv.appendChild(rRightDown);
        var rLeftDown = document.createElement("div");
        rLeftDown.className = "CL9999101105KUY2EBZZ";
        rLeftDown.id = rLeftDownId;
        mydiv.appendChild(rLeftDown);
        var rRightUp = document.createElement("div");
        rRightUp.className = "CL99991011052WX0MOY7";
        rRightUp.id = rRightUpId;
        mydiv.appendChild(rRightUp);
        var rLeftUp = document.createElement("div");
        rLeftUp.className = "CL9999101105AKT7D3EA";
        rLeftUp.id = rLeftUpId;
        mydiv.appendChild(rLeftUp);
        var rRight = document.createElement("div");
        rRight.className = "CL9999101105FOV1F2NC";
        rRight.id = rRightId;
        mydiv.appendChild(rRight);
        var rLeft = document.createElement("div");
        rLeft.className = "CL9999101105ZD5FX2O8";
        rLeft.id = rLeftId;
        mydiv.appendChild(rLeft);
        var rUp = document.createElement("div");
        rUp.className = "CL9999101105JC1MWONS";
        rUp.id = rUpId;
        mydiv.appendChild(rUp);
        var rDown = document.createElement("div");
        rDown.className = "CL99991011054AFWDB9W";
        rDown.id = rDownId;
        mydiv.appendChild(rDown);
        var pos = this.getElementPos(id);
        mydiv.style.left = (pos.x + document.getElementById(id).offsetWidth + 5) + "px";
        mydiv.style.top = (pos.y + document.getElementById(id).offsetHeight + 5) + "px";
        document.body.appendChild(mydiv);
        
		
        var resetScrollbar = function(){
            scrolldiv.style.height = (contentdiv.offsetHeight - scrolldiv.offsetTop - 2) + "px";
            if (contentdiv.offsetHeight - contents.offsetHeight >= 0) {
                scrollbardiv.style.height = scrollctdiv.offsetHeight + "px";
                scrollbardiv.style.top = "0px";
                contents.style.top = "0px";
                scrollbardiv.style.display = "none";
            }
            else {
            
            
                if (contents.offsetHeight + contents.offsetTop < contentdiv.offsetHeight) {
                
                    contents.style.top = (contentdiv.offsetHeight - contents.offsetHeight) + "px";
                    var h = contents.offsetHeight - contentdiv.offsetHeight;
                    if (h > scrollctdiv.offsetHeight - 10) {
                        h = scrollctdiv.offsetHeight - 10;
                    }
                    scrollbardiv.style.top = h + "px";
                    scrollbardiv.style.height = (scrollctdiv.offsetHeight - h) + "px";
                }
                else {
                    var h = (scrollctdiv.offsetHeight - (contents.offsetHeight - contentdiv.offsetHeight));
                    if (h < 10) {
                        h = 10;
                    }
                    scrollbardiv.style.height = h + "px";
                    contents.style.top = (-scrollbardiv.offsetTop * ((contents.offsetHeight - contentdiv.offsetHeight) / (scrollctdiv.offsetHeight - h))) + "px";
                }
                scrollbardiv.style.display = "inline";
            }
        }
        var rs = new this.Resize(this, mydivid, {
            Max: true,
            Min: true,
            onResize: resetScrollbar
        });
        
        rs.Set(rRightDownId, "right-down");
        rs.Set(rLeftDownId, "left-down");
        
        rs.Set(rRightUpId, "right-up");
        rs.Set(rLeftUpId, "left-up");
        
        rs.Set(rRightId, "right");
        rs.Set(rLeftId, "left");
        
        rs.Set(rUpId, "up");
        rs.Set(rDownId, "down");
        
        
        resetScrollbar();
        new this.Drag(this, mydivid, {
            Limit: true,
            Handle: contentdivid
        });
        new this.Drag(this, scrollbardivid, {
            Limit: true,
            mxContainer: scrollctdivid,
            onMove: resetScrollbar
        });
        
        return {
            el: contents,
            fn: resetScrollbar
        };
    };
    this.changeColor = function(ele, targetele, fromcolor, tocolor, millisec, times, index, ti){
        var that = this;
        if (index >= times) {
            targetele.style.backgroundColor = tocolor;
            if (ti == 3) {
                targetele.style.backgroundColor = "transparent";
                return;
            }
            setTimeout(function(){
                that.changeColor(ele, targetele, tocolor, fromcolor, millisec, times, 0, ti + 1);
            }, millisec);
            return;
        }
        fr = this.HexToR(fromcolor);
        fg = this.HexToG(fromcolor);
        fb = this.HexToB(fromcolor);
        tr = this.HexToR(tocolor);
        tg = this.HexToG(tocolor);
        tb = this.HexToB(tocolor);
        
        
        sr = fr + (tr - fr) / times * (index + 1);
        sg = fg + (tg - fg) / times * (index + 1);
        sb = fb + (tb - fb) / times * (index + 1);
        scolor = this.RGBtoHex(sr, sg, sb);
        targetele.style.backgroundColor = scolor;
        setTimeout(function(){
            that.changeColor(ele, targetele, fromcolor, tocolor, millisec, times, index + 1, ti);
        }, millisec);
    };
    this.popMessage = function(sid){
        this.esid = document.getElementById(sid)
        if (this.esid) {
            color = this.getStyle(this.esid.parentNode, "backgroundColor");
            color = this.colorToHex(color);
            this.changeColor(this.esid.parentNode, this.esid, color, "#FEE47E", 50, 10, 0, 0);
            var pos = this.getElementPos(this.esid.id);
            scrollTo(pos.x - this.getViewportWidth() / 2, pos.y - this.getViewportHeight() / 2);
        }
    };
}
var myecode = new ECode();
